<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:sisguia="http://guiav6.com.br/sisguia"
	template="/pages/template/layoutAdmin.xhtml">

<ui:define name="body">

	<link rel="stylesheet" type="text/css" href="#{request.contextPath}/css/selectable-firefox.css" />
	<link rel="stylesheet" type="text/css" href="#{request.contextPath}/css/jquery-ui.css" />

	<h:form prependId="false" id="form">
	
		<h:panelGroup layout="block" id="cadastro">
		
			<h:panelGroup layout="block" id="txtInformativoPagina">
				<h:outputText value="#{msg['label.dados.empresa']}" />
			</h:panelGroup>
		
			<h:panelGroup layout="block" styleClass="painelEsquerdo">
		
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.nome.empresa']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.nomeFantasia}" size="40" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.cnpj.cpf']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.cnpjCpf}" size="40" maxlength="14" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.servico']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm" id="panelTipoServico">
					<p:selectOneMenu value="#{empresaAction.idTipoServico}" valueChangeListener="#{empresaAction.findEspecialidadeByTipoServico}" styleClass="comboFormPadrao">
						<f:selectItem itemLabel="Selecione" itemValue="0" />
						<f:selectItems value="#{empresaAction.servicoSelectItem}" />
						<p:ajax event="change" update="panelEspecialidade"></p:ajax>
					</p:selectOneMenu>
				</h:panelGroup>
				
				<h:panelGroup id="panelEspecialidade">
					<h:panelGroup layout="block" rendered="#{empresaAction.idTipoServico != null and empresaAction.idTipoServico != 0}">
						<h:panelGroup layout="block" styleClass="divLabelForm">
							<h:outputLabel value="#{msg['label.especialidade']}"></h:outputLabel>
						</h:panelGroup>
						<h:panelGroup layout="block" styleClass="divInputForm">
							<p:selectOneMenu value="#{empresaAction.idEspecialidade}" styleClass="comboFormPadrao">
								<f:selectItem itemLabel="#{msg['label.nao.informada']}" itemValue="0" />
								<f:selectItems value="#{empresaAction.especialidadeSelectItem}" />
							</p:selectOneMenu>
							<p:spacer width="10" />
							<p:commandLink ajax="true" actionListener="#{empresaAction.addServico}" update=":msgSistemaGeral panelServicos panelTipoServico panelEspecialidade">
								<h:graphicImage value="/img/btn_add.png" />
							</p:commandLink>
						</h:panelGroup>
					</h:panelGroup>
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.email']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.email}" size="40" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.site']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.site}" size="40" />
				</h:panelGroup>
				
				<h:panelGroup id="panelServicos">
					<h:panelGroup layout="block" styleClass="divLabelForm" rendered="#{not empty empresaAction.empresa.tipoServicoEmpresaList}">
						<p:treeTable value="#{empresaAction.root}" var="node">
							<f:facet name="header">
								<h:outputText value="#{msg['label.servicos']}" />
							</f:facet>
							<p:column>
								<h:outputText value="#{node}" />
							</p:column>
						</p:treeTable>
					</h:panelGroup>
				</h:panelGroup>
				
			</h:panelGroup>
				
			<h:panelGroup layout="block" styleClass="painelDireito">
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.cep']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:inputText value="${empresaAction.empresa.endereco.cep}" maxlength="8" size="15" />
					<p:spacer width="10" />
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:commandLink ajax="true" actionListener="#{empresaAction.findEnderecoByCep}" update="cadastro panelMapa" oncomplete="wdgMapa.show();">
						<h:graphicImage value="/img/btn_add.png" />
					</p:commandLink>
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.bairro']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.endereco.bairro.nome}" size="40" readonly="true" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.logradouro']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.endereco.logradouro}" size="40" readonly="true" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.complemento']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputForm">
					<p:inputText value="${empresaAction.empresa.endereco.complemento}" size="40" />
				</h:panelGroup>
				
				<h:panelGroup layout="block" styleClass="divLabelForm">
					<h:outputLabel value="#{msg['label.telefone']}"></h:outputLabel>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:inputText value="${empresaAction.nuDdd}" size="2" maxlength="2" />
					<p:spacer width="10" />
					<p:inputText value="${empresaAction.nuTelefone}" size="8" maxlength="8" />
					<p:spacer width="10" />
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="divInputAddForm">
					<p:commandLink ajax="true" actionListener="#{empresaAction.addTelefone}" update=":msgSistemaGeral panelTelefoneList">
						<h:graphicImage value="/img/btn_add.png" />
					</p:commandLink>
				</h:panelGroup>
				
				<p:dialog id="panelMapa" resizable="false" width="540" height="390" header="${empresaAction.empresa.endereco.logradouro}" showEffect="clip" widgetVar="wdgMapa">
					<h:panelGroup layout="block" id="mapa">
						<div style="background-image: url('#{request.contextPath}#{empresaAction.empresa.pathMapa}'); width: 500px; height: 352px; position: relative;">
							<ui:repeat var="bloco" value="#{sisguia:mapToList(empresaAction.blocoMap)}">
								<div>
									<span>
										<p:commandLink actionListener="#{empresaAction.selectBloco}" ajax="true" update=":form:mapa">
											<p:graphicImage value="/img/bloco_selecao.png" style="position: absolute; top: #{bloco.value[0]}px; left: #{bloco.value[1]}px;" />
											<p:graphicImage value="/img/bloco_selecionado.png" style="position: absolute; top: #{bloco.value[0]}px; left: #{bloco.value[1]}px;" rendered="#{empresaAction.empresa.endereco.bloco == bloco.key}" />
											<f:param name="bloco" value="#{bloco.key}"/>
										</p:commandLink>
									</span>
								</div>
							</ui:repeat>
						</div>
					</h:panelGroup>
				</p:dialog>
				
				<h:panelGroup id="panelTelefoneList">
					<h:panelGroup layout="block" styleClass="divLabelForm">
							<h:panelGroup layout="block" rendered="#{not empty empresaAction.empresa.telefoneList}">
								<p:dataList value="#{empresaAction.empresa.telefoneList}" var="tel" type="ordered">
									<f:facet name="header">
										<h:outputText value="#{msg['label.telefones']}" />
									</f:facet>
									<p:column>
										<h:outputText value="(#{tel.ddd}) #{tel.telefone}" />
									</p:column>
								</p:dataList>
							</h:panelGroup>
					</h:panelGroup>
				</h:panelGroup>

			</h:panelGroup>
			
		</h:panelGroup>
		
		<h:panelGroup layout="block" styleClass="clearAll">
		</h:panelGroup>
		
		<h:panelGroup layout="block" styleClass="buttonFormBar">
			<h:panelGroup layout="block" styleClass="divInputForm">
				<p:commandLink ajax="true" actionListener="#{empresaAction.atualizar}" update=":msgSistemaGeral">
					<h:graphicImage value="/img/btn_cadastrar.png" />
				</p:commandLink>
			</h:panelGroup>
		</h:panelGroup>

	</h:form>
	
</ui:define>

</ui:composition>